package remin;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.sql.*;

public class PFLis implements ActionListener{
	
	String insert;	
	Refr ref = new Refr();
				
	
		public void actionPerformed(ActionEvent evt){
		
		String com = evt.getActionCommand();
		String priorita,dd,mm,rok,hh,mi,predmet,poznamka;
		int id = 0; 
		
		if(com =="OK,pridaj"){
			try {
			
			Statement s = DBCon.conn.createStatement();
            s.executeQuery("select max(idrem) from reminder");
            ResultSet rs = s.getResultSet();
            
            while(rs.next()){
            int last = (rs.getInt(1));
            id = ++last;
            }
            
            
			
			dd = PridForm.den.getText();
			mm = PridForm.mesiac.getText();
			rok = PridForm.rok.getText();
			hh = PridForm.hod.getText();
			mi = PridForm.min.getText();
			predmet = PridForm.pret.getText();
			poznamka = PridForm.pozt.getText();
			Object kto = PridForm.priot.getSelectedItem();
			priorita = kto.toString();
			
			insert = "insert into reminder values('" + id + "',TO_DATE('" +
			dd + "-" + mm + "-" + rok + " " + hh + ":" + mi +"','DD-MM-YY HH24:MI'),'" +
			predmet + "','" + priorita + "','" + poznamka + "')";
			RemGui.comm.setText("gombik stlaceny...");
			System.out.println(insert);
			Statement st = DBCon.conn.createStatement();
            st.executeUpdate(insert);
            ref.refr();
            //tu bol refresh udalosti
            
            RemGui.comm.setText("Pridane...");
            
			} 
			catch(Exception e)
			{
				RemGui.comm.setText("Nepodarilo sa pridat...");
			}
			
		}
		else if(com =="Vymaz formular"){
			PridForm.den.setText("");
			PridForm.mesiac.setText("");
			PridForm.rok.setText("");
			PridForm.hod.setText("");
			PridForm.min.setText("");
			PridForm.pret.setText("");
			PridForm.pozt.setText("");
		}
	}
	
}
